package cn.kooki.app.duobao.ui.Adapter;

import android.content.Context;
import android.graphics.Paint;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.StrikethroughSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.kooki.app.duobao.R;
import cn.kooki.app.duobao.data.Bean.User.pay.PaylistItem;
import cn.kooki.app.duobao.util.TimeUtils;

/**
 * Created by xionghao on 15/12/26.
 */
public class PayListAdapter extends BaseAdapter {

    private ArrayList<PaylistItem> datas;
    private Context context;

    public PayListAdapter(Context context, ArrayList<PaylistItem> datas) {
        this.context = context;
        this.datas = datas;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        PaylistItem item = datas.get(position);
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.layout_chargerecord, parent, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tvBankName.setText(item.getPay_type());
        viewHolder.tvAmount.setText(item.getMoney());
        viewHolder.tvTime.setText(TimeUtils.getTime(item.getTime()));
        SpannableStringBuilder builder = new SpannableStringBuilder(item.getMoney());

        if (!item.getStatus().equals("已付款")) {
            builder.setSpan(new StrikethroughSpan(), 0, item.getMoney().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        viewHolder.tvAmount.setText(builder);
        viewHolder.tvOverdue.setText(item.getStatus());
        return convertView;
    }

    /**
     * This class contains all butterknife-injected Views & Layouts from layout file 'layout_chargerecord.xml'
     * for easy to all layout elements.
     *
     * @author ButterKnifeZelezny, plugin for Android Studio by Avast Developers (http://github.com/avast)
     */
    static class ViewHolder {
        @Bind(R.id.tv_bankName)
        TextView tvBankName;
        @Bind(R.id.tv_time)
        TextView tvTime;
        @Bind(R.id.tv_amount)
        TextView tvAmount;
        @Bind(R.id.tv_overdue)
        TextView tvOverdue;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
